﻿@{
    ViewBag.Title = "FileList";
    List<KingRoad.EPM.ProjectFileEntity.FILE_FILEINFO> FileList = ViewBag.FileList as List<KingRoad.EPM.ProjectFileEntity.FILE_FILEINFO>;
}
@using System.Collections.Generic
@using KingRoad.EPM.Common.Helper
<script type="text/javascript">
    $(function () {
        $('#Common_UploaderFile_UpLoader_Form_FileLoad').uploadify({
            'uploader': '/Scripts/uploadify/uploadify.swf?id=' + (new Date()).getTime(),
            'script': '@ViewBag.Path' + "/Home/Upload", //'/Common/UploaderFile/UploadFile', // + FileUrl
            'cancelImg': '/Scripts/uploadify/cancel.png',
            'queueID': 'Common_UploaderFile_AddFile_fileQueue',
            'wmode': 'transparent',
            'buttonImg': '/Scripts/uploadify/button.gif',
            'multi': true,
            'method': 'Post',
            'auto': true,
            'sizeLimit': '2048000000',
            //            'queueSizeLimit':5,
            'removeCompleted': false,
            'scriptData': { "dirPath": escape("@ViewBag.FilePath") },
            'onComplete': function (event, queueID, fileObj, response, data) {
            },
            'onError': function (event, queueID, fileObj, errorObj) {
                alertMsg.warn(errorObj.type + "Error:" + errorObj.info);
            }
        });
    });
    function fun_PreViewDoc_UploadFile(obj, fileId) {
        var prevPath = $(obj).attr("readpath");
        var extendName = $(obj).attr("extendname").toLowerCase();
        //可预览格式处理
        if (extendName == "jpg" || extendName == "jpeg" || extendName == "png" || extendName == "gif" || extendName == "bmp" || extendName == "tiff") {
            fun_preViewImgOnMask_uploadFile(prevPath);
        } else if (extendName == "mp4" || extendName == "avi" || extendName == "rmvb" || extendName == "3gp" || extendName == "flv") {
            $.pdialog.open("/File/File/Preview?src=" + escape(prevPath), "", "", { "mask": "true", width: 800, height: 600 });
        } else if (extendName == "pdf") {
            window.open("@ViewBag.Path/Home/LoadPdf?fileId=" + fileId);
        } else if (extendName == "doc" || extendName == "docx" || extendName == "xls" || extendName == "xlsx") {
            window.open("/File/File/OffPreview?fileId=" + fileId);
        } else {
            alertMsg.info("文件格式不支持预览");
        }
    }
    //打开遮罩层
    function fun_preViewImgOnMask_uploadFile(path) {
        document.getElementById('backgroundInstructions').style.display = 'block'; //打开遮罩层
        $("#backgroundInstructions").append("<div style='width:840px;height:600px;position:absolute;z-index:1112;top:50%;left:50%;margin-left:-420px;margin-top:-300px;overflow-y:scroll;'><img id = 'img' src='" + path + "'style='display:block; width:100%;height:auto;' /></div>"); //加载图片
        $("#backgroundInstructions").append("<span id = 'Close' onclick='OffMask()'></span>"); //加载关闭按钮
    }
</script>
<div class="uploadBox" style="border-top:none;margin-bottom:10px;">
<input type="text" id="Common_UploaderFile_UpLoader_Form_FileLoad" value="" />
</div>
<table class="tables tables-bordered tables-hover" style="border-left:1px solid #d9d9d9;border-top:1px solid #d9d9d9;">
    <thead>
        <tr>
            <th style="display: none; text-align: center">
            </th>
            <th style="width: 50%; text-align: center">
                文件名称
            </th>
            <th style="width: 30%; text-align: center">
                上传时间
            </th>
            <th style="width: 20%; text-align: center">
                操作
            </th>
        </tr>
    </thead>
    <tbody id="Common_UploaderFile_UpLoader_fileTbody">
        @{
            if (FileList != null)
            {
                for (int i = 0; i < FileList.Count; i++)
                {
            <tr fielid="@FileList[i].FILE_ID">
                <td style="display: none">@FileList[i].FILE_ID
                </td>
                <td style="text-align: center">@FileList[i].FILE_NAME
                </td>
                <td style="text-align: center">@FileList[i].FILE_TIME
                </td>
                <td style="text-align: center; color: blue">
                    <nobr>
                    @if (FileList[i].FILE_USERID == DotNet.Service.UserService.CurrUserInfo.Id)
                    {
                        <a href="javascript:fun_Delete_Common_FileList(@FileList[i].FILE_ID,@FileList[i].DeleteID);" id="Delete_common_uploaderfile_filelist" class="tabIcon iconCol_03 delete" title="删除">
                        </a>
                            
                    }
                    @if (!string.IsNullOrWhiteSpace(FileList[i].DownloadPath))
                    {
                        <a href="@Html.Raw(ViewBag.Path + "/Home/DownLoadFile?fileId=" + @FileList[i].FILE_ID)" class="tabIcon iconCol_03 download" target="_blank" title="下载">
                        </a>
                    }
                    @if (!string.IsNullOrWhiteSpace(FileList[i].ReadPath))
                    {
                        <a href="javascript:void(0);" onclick="fun_PreViewDoc_UploadFile(this,@FileList[i].FILE_ID)" class="tabIcon iconCol_03 preview"  title="预览" readpath="@FileList[i].ReadPath" extendname="@FileList[i].ExtendName">
                        </a>
                    }
                    </nobr>
                </td>
            </tr>
                }
            }
        }
    </tbody>
</table>
